package cn.kgc.jdbc.service;

import cn.kgc.jdbc.dao.*;
import cn.kgc.jdbc.entity.Course;
import cn.kgc.jdbc.entity.Score;
import cn.kgc.jdbc.entity.Student;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/4/22
 */
public class ScoreServiceImpl implements ScoreService {

    private StudentDao studentDao = new StudentDaoImpl();
    private ScoreDao scoreDao = new ScoreDaoImpl();
    private CourseDao courseDao = new CourseDaoImpl();

    @Override
    public boolean addScore(String stuName, String courseName,double score) {
        //成绩表中记录的时学生的id以及科目id  成绩
        //1.根据学生的姓名 查询学生的学号
        Student student = studentDao.selectByName(stuName);
        long stuId = student.getId();
        // 2.根据科目的名称查询科目编号
        Course course = courseDao.selectByName(courseName);
        long courseId = course.getId();
        // 3.将学生id  科目id  分数添加到score表
        int line =  scoreDao.addScore(stuId,courseId,score);
        return line > 0;
    }

    @Override
    public List<Score> selectAll(String courseName) {

        List<Score> scores =  scoreDao.selectAll(courseName);
        return scores;
    }
}
